<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>lunar-老黄历</title>
<meta name="keywords" content="lunar,阳历,阴历,公历,农历" />
<meta name="description" content="lunar是一个无依赖的支持阳历和阴历的日历工具库。" />
<meta name="author" content="6tail" />
<link rel="stylesheet" href="common.css">
<link rel="stylesheet" href="highlight.min.css">
<link rel="stylesheet" href="markdown.css">
<link rel="stylesheet" href="page.css">
<style type="text/css">
.line{
  margin:20px;
}
.line input{
  padding:5px;
}
.huangli{}
.huangli div{
  margin-top:20px;
}
.markdown-body td a{
  margin-left:2px;
  color:#007CD5;
  padding:0 6px;
  -webkit-border-radius:50%;
 -moz-border-radius:50%;
 -ms-border-radius:50%;
 -o-border-radius:50%;
 border-radius:50%;
}
.markdown-body td a:hover{
  background:#007CD5;
  color:#fff;
  text-decoration:none;
}
</style>
</head>
<body>
<div class="article">
<textarea class="md">
## 老黄历

请填写阳历（公历）时间：
</textarea>
<div class="line">年：<input id="year" type="text"></div>
<div class="line">月：<input id="month" type="text"></div>
<div class="line">日：<input id="day" type="text"></div>

<div class="huangli">
  <table>
    <tbody>
      <tr>
        <td width="120">公历</td>
        <td id="c"></td>
      </tr>
      <tr>
        <td>农历</td>
        <td id="b"></td>
      </tr>
      <tr>
        <td>佛历<a href="foto.new.html">?</a></td>
        <td id="foto"></td>
      </tr>
      <tr>
        <td>道历<a href="tao.new.html">?</a></td>
        <td id="tao"></td>
      </tr>
      <tr>
        <td>年</td>
        <td id="a"></td>
      </tr>
      <tr>
        <td>月</td>
        <td id="a1"></td>
      </tr>
      <tr>
        <td>日</td>
        <td id="a2"></td>
      </tr>
      <tr>
        <td>儒略日<a href="solar.jd.html">?</a></td>
        <td id="a3"></td>
      </tr>
      <tr>
        <td>月名</td>
        <td id="m"></td>
      </tr>
      <tr>
        <td>月相<a href="lunar.yuexiang.html">?</a></td>
        <td id="yuexiang"></td>
      </tr>
      <tr>
        <td>物候<a href="lunar.wuhou.html">?</a></td>
        <td id="wuhou"></td>
      </tr>
      <tr>
        <td>三元九运<a href="lunar-year.sanyuanjiuyun.html">?</a></td>
        <td id="syjy"></td>
      </tr>
      <tr>
        <td>治水<a href="lunar-year.zaomatou.html">?</a></td>
        <td id="zhishui"></td>
      </tr>
      <tr>
        <td>分饼<a href="lunar-year.zaomatou.html">?</a></td>
        <td id="fenbing"></td>
      </tr>
      <tr>
        <td>耕田<a href="lunar-year.zaomatou.html">?</a></td>
        <td id="gengtian"></td>
      </tr>
      <tr>
        <td>得金<a href="lunar-year.zaomatou.html">?</a></td>
        <td id="dejin"></td>
      </tr>
      <tr>
        <td>日禄<a href="lunar.lu.html">?</a></td>
        <td id="rilu"></td>
      </tr>
      <tr>
        <td>六曜<a href="lunar.liuyao.html">?</a></td>
        <td id="liuyao"></td>
      </tr>
      <tr>
        <td>彭祖百忌<a href="lunar.pengzu.html">?</a></td>
        <td id="d"></td>
      </tr>
      <tr>
        <td>每日宜忌<a href="lunar.yiji.html">?</a></td>
        <td id="yj"></td>
      </tr>
      <tr>
        <td>吉神宜趋<a href="lunar.jishenxiongsha.html">?</a></td>
        <td id="js"></td>
      </tr>
      <tr>
        <td>凶煞宜忌<a href="lunar.jishenxiongsha.html">?</a></td>
        <td id="xs"></td>
      </tr>
      <tr>
        <td>相冲<a href="lunar.chongsha.html">?</a></td>
        <td id="e"></td>
      </tr>
      <tr>
        <td>岁煞<a href="lunar.chongsha.html">?</a></td>
        <td id="f"></td>
      </tr>
      <tr>
        <td>星宿<a href="lunar.xiu.html">?</a></td>
        <td id="g"></td>
      </tr>
      <tr>
        <td>星宿歌诀<a href="lunar.xiu.html">?</a></td>
        <td id="g1"></td>
      </tr>
      <tr>
        <td>贵神方位<a href="lunar.jishen.html">?</a></td>
        <td id="h"></td>
      </tr>
      <tr>
        <td>喜神方位<a href="lunar.jishen.html">?</a></td>
        <td id="i"></td>
      </tr>
      <tr>
        <td>福神方位<a href="lunar.jishen.html">?</a></td>
        <td id="i1"></td>
      </tr>
      <tr>
        <td>财神方位<a href="lunar.jishen.html">?</a></td>
        <td id="i2"></td>
      </tr>
      <tr>
        <td>本月胎神<a href="lunar.taishen.html">?</a></td>
        <td id="i3"></td>
      </tr>
      <tr>
        <td>今日胎神<a href="lunar.taishen.html">?</a></td>
        <td id="i4"></td>
      </tr>
      <tr>
        <td>太岁方位</td>
        <td id="i5"></td>
      </tr>
      <tr>
        <td>值星<a href="lunar.zhixing.html">?</a></td>
        <td id="j"></td>
      </tr>
      <tr>
        <td>十二天神<a href="lunar.tianshen.html">?</a></td>
        <td id="k"></td>
      </tr>
      <tr>
        <td>空亡所值<a href="lunar.xun.html">?</a></td>
        <td id="xun"></td>
      </tr>
      <tr>
        <td>九星<a href="lunar.nine.html">?</a></td>
        <td id="jiuxing"></td>
      </tr>
      <tr>
        <td>九星歌诀<a href="lunar.nine.html">?</a></td>
        <td id="jiuxing-song"></td>
      </tr>
      <tr>
        <td>上一节气</td>
        <td id="p"></td>
      </tr>
      <tr>
        <td>下一节气</td>
        <td id="n"></td>
      </tr>
      <tr>
        <td>节日/纪念日</td>
        <td id="x"></td>
      </tr>
      <tr>
        <td>数九<a href="lunar.shujiu.html">?</a></td>
        <td id="shuJiu"></td>
      </tr>
      <tr>
        <td>三伏<a href="lunar.fu.html">?</a></td>
        <td id="fu"></td>
      </tr>
    </tbody>
  </table>
  
  <div id="times"></div>
</div>

<div style="color:#999;">经常有人问各项数据怎么取的，请点击问号查看对应文档。也经常有人问怎么生成每天的时辰列表，请参考<a href="lunar.time.html">获取时辰</a>。</div>

</div>
<script src="libs/jquery.min.js"></script>
<script src="libs/highlight.min.js"></script>
<script src="libs/marked.min.js"></script>
<script src="common-source.js"></script>
<script src="lunar.js"></script>
<script>
mdr('.md');
</script>
<script>
(function(){
  var today = Solar.fromDate(new Date());
  $('#year').val(today.getYear());
  $('#month').val(today.getMonth());
  $('#day').val(today.getDay());
  
  var throttle = function(fn,delay,atleast){
    var timer = null;
    var previous = null;
    return function(){
      var now = +new Date();
      if(!previous) previous = now;
      if(atleast && now - previous > atleast){
        fn();
        previous = now;
        clearTimeout(timer);
      } else {
        clearTimeout(timer);
        timer = setTimeout(function(){
          fn();
          previous = null;
        }, delay);
      }
    }
  };
  
  var onChange = throttle(function(){
    compute();
  },20,50);
  
  // 生成时辰表
  var renderTime = function(lunar){
    var l = lunar.getTimes();
    var s = '<table><tbody>';
    
    s += '<tr><td width="9%">时辰</td>';
    for(var i=0,j=l.length;i<j;i++){
      s += '<td width="7%">'+l[i].getGanZhi()+'</td>';
    }
    s += '</tr>';
    
    s += '<tr><td>时刻</td>';
    for(var i=0,j=l.length;i<j;i++){
      s += '<td width="7%">'+l[i].getMinHm()+'-'+l[i].getMaxHm()+'</td>';
    }
    s += '</tr>';
    
    s += '<tr><td>天神<a href="lunar.tianshen.html">?</a></td>';
    for(var i=0,j=l.length;i<j;i++){
      s += '<td>'+l[i].getTianShen()+'</td>';
    }
    s += '</tr>';
    
    s += '<tr><td>黑黄道<a href="lunar.tianshen.html">?</a></td>';
    for(var i=0,j=l.length;i<j;i++){
      s += '<td>'+l[i].getTianShenType()+'</td>';
    }
    s += '</tr>';
    
    s += '<tr><td>吉凶<a href="lunar.tianshen.html">?</a></td>';
    for(var i=0,j=l.length;i<j;i++){
      s += '<td>'+l[i].getTianShenLuck()+'</td>';
    }
    s += '</tr>';
    
    s += '<tr><td>冲<a href="lunar.chongsha.html">?</a></td>';
    for(var i=0,j=l.length;i<j;i++){
      s += '<td>'+l[i].getChongDesc()+'</td>';
    }
    s += '</tr>';
    
    s += '<tr><td>煞<a href="lunar.chongsha.html">?</a></td>';
    for(var i=0,j=l.length;i<j;i++){
      s += '<td>'+l[i].getSha()+'</td>';
    }
    s += '</tr>';
    
    s += '<tr><td>宜<a href="lunar.timeyiji.html">?</a></td>';
    for(var i=0,j=l.length;i<j;i++){
      s += '<td>'+l[i].getYi().join(' ')+'</td>';
    }
    s += '</tr>';
    
    s += '<tr><td>忌<a href="lunar.timeyiji.html">?</a></td>';
    for(var i=0,j=l.length;i<j;i++){
      s += '<td>'+l[i].getJi().join(' ')+'</td>';
    }
    s += '</tr>';
    
    s += '</tbody></table>';
    $('#times').html(s);
  };

  var compute = function(){
    try{
      var year = $('#year').val();
      var month = $('#month').val();
      var day = $('#day').val();
      if(year<1||year>9999){
        return;
      }
      if(month<1||month>12){
        return;
      }
      if(day<1||day>31){
        return;
      }
      year = parseInt(year,10);
      month = parseInt(month,10);
      day = parseInt(day,10);
      var s = Solar.fromYmd(year,month,day);
      var h = HolidayUtil.getHoliday(year, month, day);
      var d = s.getLunar();
      var foto = d.getFoto();
      var tao = d.getTao();
      $('#foto').html(foto.getYearInChinese()+'年 '+foto.getMonthInChinese()+'月 '+foto.getDayInChinese());
      $('#tao').html(tao.getYearInChinese()+'年 '+tao.getMonthInChinese()+'月 '+tao.getDayInChinese());
      $('#yuexiang').html(d.getYueXiang());
      $('#a').html(d.getYearInGanZhi()+'年 属'+d.getYearShengXiao()+' '+d.getYearNaYin());
      $('#a1').html(d.getMonthInGanZhi()+'月 属'+d.getMonthShengXiao()+' '+d.getMonthNaYin());
      $('#a2').html(d.getDayInGanZhi()+'日 属'+d.getDayShengXiao()+' '+d.getDayNaYin());
      $('#a3').html(s.getJulianDay());
      $('#b').html(d.getYearInChinese()+'年 '+d.getMonthInChinese()+'月 '+d.getDayInChinese()+' (阴历)');
      $('#c').html(s.getYear()+'年 '+s.getMonth()+'月 '+s.getDay()+'日 星期'+s.getWeekInChinese()+' '+s.getXingZuo()+'座 (阳历)');
      $('#m').html(d.getSeason());
      $('#d').html(d.getPengZuGan()+' '+d.getPengZuZhi());
      $('#yj').html('<span style="color:green">宜</span>：'+d.getDayYi().join(' ')+'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:red">忌</span>：'+d.getDayJi().join(' '));
      $('#e').html(d.getDayShengXiao()+'日 冲'+d.getChongDesc());
      $('#js').html(d.getDayJiShen().join(' '));
      $('#xs').html(d.getDayXiongSha().join(' '));
      $('#f').html(d.getSha());
      $('#g').html(d.getGong()+'方'+d.getXiu()+d.getZheng()+d.getAnimal()+' ('+d.getXiuLuck()+')');
      $('#g1').html(d.getXiuSong());
      $('#h').html('阳贵神：'+d.getPositionYangGuiDesc()+' 阴贵神：'+d.getPositionYinGuiDesc());
      $('#i').html(d.getPositionXiDesc());
      $('#i1').html(d.getPositionFuDesc());
      $('#i2').html(d.getPositionCaiDesc());
      $('#i3').html(d.getMonthPositionTai());
      $('#i4').html(d.getDayPositionTai());
      $('#i5').html(d.getDayPositionTaiSuiDesc());
      
      var fs = [];
      var f = d.getFestivals();
      if (f) {
        for (var i=0,j=f.length;i<j;i++){
          fs.push(f[i]);
        }
      }
      f = d.getOtherFestivals();
      if (f) {
        for (var i=0,j=f.length;i<j;i++){
          fs.push(f[i]);
        }
      }
      f = s.getFestivals();
      if (f) {
        for (var i=0,j=f.length;i<j;i++){
          fs.push(f[i]);
        }
      }
      f = s.getOtherFestivals();
      if (f) {
        for (var i=0,j=f.length;i<j;i++){
          fs.push(f[i]);
        }
      }
      f = foto.getFestivals();
      if (f) {
        for (var i=0,j=f.length;i<j;i++){
          fs.push(f[i]);
        }
      }
      f = tao.getFestivals();
      if (f) {
        for (var i=0,j=f.length;i<j;i++){
          fs.push(f[i]);
        }
      }
      if (h) {
        fs.push(h.getName()+(h.isWork()?'调休':'放假'));
      }
      $('#x').html(fs.join('、'));
      $('#j').html(d.getZhiXing());
      $('#k').html(d.getDayTianShen()+'('+d.getDayTianShenType()+') '+ d.getDayTianShenLuck());
      var p = d.getPrevJieQi(),n = d.getNextJieQi();
      $('#p').html(p.getName()+' '+p.getSolar().toYmdHms()+' 星期'+p.getSolar().getWeekInChinese());
      $('#n').html(n.getName()+' '+n.getSolar().toYmdHms()+' 星期'+n.getSolar().getWeekInChinese());
      
      var jiuxing = d.getDayNineStar();
      $('#jiuxing').html(jiuxing.getNumber()+jiuxing.getColor()+' - '+jiuxing.getNameInTaiYi()+'星('+jiuxing.getWuXing()+') - '+jiuxing.getTypeInTaiYi());
      $('#jiuxing-song').html(jiuxing.getSongInTaiYi());
      
      $('#xun').html('年：'+d.getYearXunKong()+'&nbsp;&nbsp;&nbsp;月：'+d.getMonthXunKong()+'&nbsp;&nbsp;&nbsp;日：'+d.getDayXunKong());
      
      var shuJiu = d.getShuJiu();
      $('#shuJiu').html(shuJiu ? shuJiu.toFullString() : '');
      
      var fu = d.getFu();
      $('#fu').html(fu ? fu.toFullString() : '');
      
      // 物候
      $('#wuhou').html(d.getHou() + '，' +d.getWuHou());
      
      // 六曜
      $('#liuyao').html(d.getLiuYao());
      
      // 日禄
      $('#rilu').html(d.getDayLu());
      
      var lunarYear = LunarYear.fromYear(d.getYear());
      //三元九运
      $('#syjy').html(lunarYear.getYuan() + ' ' + lunarYear.getYun());
      // 治水
      $('#zhishui').html(lunarYear.getZhiShui());
      // 分饼
      $('#fenbing').html(lunarYear.getFenBing());
      // 耕田
      $('#gengtian').html(lunarYear.getGengTian());
      // 得金
      $('#dejin').html(lunarYear.getDeJin());
      
      renderTime(d);
    }catch(e){
      console.log(e);
    }
  };

  compute();

  $('#year').on('input propertychange',onChange);
  $('#month').on('input propertychange',onChange);
  $('#day').on('input propertychange',onChange);
})();
</script>
</body>
</html>